$(document).ready(function() {
    $('#PayrollDivisiId').change(function() {
        var ddcDivisi = $('#PayrollDivisiId :selected');

        $.ajax({
            type: 'get',
            url: app_root_path+'payroll_ajax/getKaryawanByDivisi',
            data: {'divisiId':ddcDivisi.val(), 'table':'potongan'},
            dataType: 'json',
            cache: 'false',
            success: function (data) {
                var ddcKaryawan = $('#PotonganKaryawanId');
                var ddcArray = [];

                for (var i=0; i<data.length; i++) {
                    if (data[i].Karyawan.id == 0) {
                        ddcArray.push('<option value="'+data[i].Karyawan.id+'" selected="selected">'+data[i].Karyawan.nama+'</option>');
                    } else {
                        ddcArray.push('<option value="'+data[i].Karyawan.id+'">'+data[i].Karyawan.nama+'</option>');
                    }
                }

                ddcKaryawan.html(ddcArray.join('')).fadeOut().fadeIn();
            }
        }
        );
    })
});